package top.chatgqt.SmartChargeStation.demo.mqtt.PahoMode.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * mqtt的回调类
 */
@Slf4j
public class Callback implements MqttCallback {

    /**
     * 连接丢失调用
     */
    @Override
    public void connectionLost(Throwable cause) {
        log.info("连接断开，原因: {}", cause.getMessage());
    }

    /**
     * 接收到订阅的消息后调用
     */
    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info("接收到消息 topic：{} message： {}", topic, message.toString());
    }

    /**
     * 发送消息后调用
     */
    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {
        log.info("消息发送结果：{}", token.isComplete());
    }
}
